package com.longtop.perform.khyg.web;

import java.util.HashMap;
import java.util.Map;

import com.longtop.framework.base.BaseAction;
import com.longtop.framework.util.WebUtil;
import com.longtop.intelliweb.action.IActionContext;
import com.longtop.intelliweb.action.IInitContext;
import com.longtop.intelliweb.view.Dataset;
import com.longtop.perform.khyg.service.TaskService;

/**
 * 
 * @author 孙景弘
 * 
 */
public class TaskUserWindowAction extends BaseAction {

	private TaskService service;
	private final String DATASET_TASK_USER = "Dataset_task_user";

	// 查询条件：
	Map<String, Object> queryMap = new HashMap<String, Object>();

	public TaskUserWindowAction() {
		this.service = this.getBean(TaskService.BEAN_ID);
	}

	/**
	 * 系统共用：初始化调用
	 */
	public void init(IInitContext context) {
		super.init(context);
	}

	/**
	 * 本页jsp：初始化业务数据(覆写父类方法)
	 */
	public void thisPageInit(IInitContext context) {
		Dataset dataset_task_user = this.getDataset(context, DATASET_TASK_USER);
		if (!WebUtil.validateDatasetExist(this, dataset_task_user, DATASET_TASK_USER))
			return;
		String segmentId = this.getParameter(context, "segmentId");
		queryMap.put("segmentId", segmentId);
		service.queryForPageByIbatis("khygTaskSql.queryTaskUser", null, queryMap, dataset_task_user, false);
	}

	/**
	 * 每个业务模块公共查询方法，供自定义查询方法及翻页查询调用
	 * 
	 * @param dataset
	 * @param context
	 * @param customAction
	 */
	private void commonQuery(IActionContext context, boolean customAction) {
		Dataset dataset_task_user = this.getDataset(context, DATASET_TASK_USER);

		if (customAction) {
			dataset_task_user.setPageNo(1);
		}
		// 查询条件：
		queryMap = this.getElementsToMap(context);
		String segmentId = this.getParameter(context, "segmentId");
		queryMap.put("segmentId", segmentId);

		service.queryForPageByIbatis("khygTaskSql.queryTaskUser", null, queryMap, dataset_task_user, false);
	}

	/**
	 * 翻页查询
	 * 
	 * @param context
	 */
	public void load(IActionContext context) {
		commonQuery(context, false);
	}

	/**
	 * 查询
	 * 
	 * @param context
	 */
	public void search(IActionContext context) {
		commonQuery(context, true);
	}
}
